// 监听cookie变更
chrome.cookies.onChanged.addListener(function(changeInfo){
    if(!changeInfo.removed && changeInfo.cookie.name.indexOf('access_token')>-1){
        chrome.tabs.query({}, function(tabs) {
            for (let i = 0; i < tabs.length; i++) {
              chrome.tabs.sendMessage(tabs[i].id, {type: "cookieChange"});
            }
        });
    }
});

// 添加右键菜单
chrome.runtime.onInstalled.addListener(function () {
    chrome.contextMenus.create({
        title: '打开页本地页面',
        id: 'openLocalThisPage',
        type: 'normal',
        contexts: ['all'],
    });
    chrome.contextMenus.create({
        title: '新打开本地页面',
        id: 'openLocal',
        type: 'normal',
        contexts: ['all'],
    });
});

// 监听菜单点击事件
chrome.contextMenus.onClicked.addListener(function(info, tab) {
    chrome.tabs.sendMessage(tab.id, info, function() {
		// console.log(arguments, chrome.runtime.lastError);
	});
});